package com.tour.config;

import org.apache.log4j.xml.DOMConfigurator;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

/**
 * @ClassName Log4jInitServlet
 * @Author 张梦兴
 * @Date 2020/3/9 16:45
 * @describe
 */
public class Log4jInitServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public Log4jInitServlet() {
        super();
    }

    /**
     * 初始化
     * @param config
     */
    @Override
    public void init(ServletConfig config) throws ServletException {
        String prefix =  config.getServletContext().getRealPath("/");
        String xml = config.getInitParameter("log4j-xml-path");
        System.out.println("初始化日志");
        if(xml != null) {
            DOMConfigurator.configure(prefix + xml);
        }
    }
}
